package com.taru.order.dao;



import com.taru.order.entity.Articl;
import com.taru.order.entity.FilePath;
import com.taru.order.util.DbUtil;

import java.util.List;

public class FileDaoImpl  {
    /**
     * 批量删除
     * @param list
     * @return
     */
    public int removePath(List list) {
        StringBuffer stringBuffer=new StringBuffer();
        for(int i=0;i<list.size();i++){
            stringBuffer.append("\'");
            stringBuffer.append(list.get(i));
            stringBuffer.append("\',");
        }
        String sql="delete from `tb_path` where id in ("+stringBuffer.substring(0,stringBuffer.length()-1)+")";
        int code= DbUtil.update(sql);
        DbUtil.close();
        return code;
    }

    /**
     * 添加图片路劲
     * @param articl
     * @return
     */
    public int addPath(Articl articl) {
        String sql="insert into `tb_path`(path,articl_code) values(?,?)";
        DbUtil.beginTransaction();
        List<FilePath> list=articl.getFilePaths();
        int code=0;
            try {
                for(FilePath filePath :list){
                    code=DbUtil.update(sql, filePath,articl.getCode());
                }
                DbUtil.commit();
            }catch (Exception e){
                DbUtil.rollback();
                e.printStackTrace();
            }
        return code;
    }
}
